package com.smarthome.core.workingmonitor.impl;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.smarthome.common.tools.BossCachedKeysUtil;
import com.smarthome.common.tools.cache.JedisUtils;
import com.smarthome.core.deviceManager.EquipmentDevCameraService;
import com.smarthome.core.workingmonitor.HaiKangVideoService;
import com.smarthome.rpc.HkVideoService;

@Service("haiKangVideoService")
public class HaiKangVideoServiceImpl implements HaiKangVideoService {

    private static Logger logger = Logger.getLogger(HaiKangVideoServiceImpl.class);
    @Resource
    private HkVideoService hkVideoService;
    @Resource
    private EquipmentDevCameraService equipmentDevCameraService;

    // @Scheduled(initialDelay = 10 * 1000, fixedRate = 5 * 24 * 60 * 60 * 1000)
    public void getToken() {
        String token = hkVideoService.getAccessToken();
        logger.info("HaiKangVideoTokenTask-getToken:" + token);
        if (!StringUtils.isBlank(token)) {
            JSONObject object = JSONObject.parseObject(token);
            JedisUtils.set(BossCachedKeysUtil.getKey(BossCachedKeysUtil.MODULE_HK_VIDEO_TOKEN, "1"), object.getJSONObject("result").getJSONObject("data").getString("accessToken"));
        }
    }

    // @Scheduled(initialDelay = 30 * 1000, fixedRate = 30 * 60 * 1000)
    public void synCameraInfo() {
        equipmentDevCameraService.parseCameraInfo();
    }

}
